import Vue from 'vue';
import router from '../router';

export const zchzhttp = {

  get(url, loader, success, error) {
    if(loader){
      loader.show();
    }
    Vue.http.get(url).then(
      (response) => {
        if(loader) {
          loader.hide();
        }
        var suc = response.data.success;
        if(suc) {
          success(response.data);
        } else {
          error(response.data);
        }
      },
      (response) => {
        if(loader) {
          loader.hide();
        }
      }
    );
  },

  post(url, param, loader, success, error) {
    if(loader){
      loader.show();
    }
    Vue.http.post(url, param).then(
      (response) => {
        if(loader) {
          loader.hide();
        }
        var suc = response.data.success;
        if(suc) {
          success(response.data);
        } else {
          error(response.data);
        }
      },
      (response) => {
        if(loader) {
          loader.hide();
        }
      }
    );
  },

  patch(url, param, loader, success, error) {
    if(loader){
      loader.show();
    }
    Vue.http.patch(url, param).then(
      (response) => {
      if(loader) {
        loader.hide();
      }
      var suc = response.data.success;
      if(suc) {
        success(response.data);
      } else {
        error(response.data);
      }
    },
      (response) => {
        if(loader) {
          loader.hide();
        }
      }
    );
  },

  delete(url, loader, success, error) {
    if(loader){
      loader.show();
    }
    Vue.http.delete(url).then(
      (response) => {
      if(loader) {
        loader.hide();
      }
      var suc = response.data.success;
      if(suc) {
        success(response.data);
      } else {
        error(response.data);
      }
    },
      (response) => {
        if(loader) {
          loader.hide();
        }
      }
    );
  }
}
